package socket.client;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.*;
 
public class TCPServer implements Runnable {
    public static final int ServerPort = 9007;
    public static final String ServerIP = "192.168.0.2";
 /**
  * 14.44.116.249
  * 
  */
    
    @Override
    public void run() {
    	
        try {
            System.out.println("S: Connecting...");
            ServerSocket serverSocket = new ServerSocket(ServerPort);
            
            while (true) {
            	Socket client =  null;
            	try {
                	client = serverSocket.accept();
                	 System.out.println("S: Receiving...");
                	Handler handler = new Handler(client);
                    handler.start();
                    
                } catch (Exception e) {
                    System.out.println("S: Error");
                    e.printStackTrace();
                } 
                finally {
                    System.out.println("S: Done.");
                }
            }
        } catch (Exception e) {
            System.out.println("S: Error");
            e.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        Thread desktopServerThread = new Thread(new TCPServer());
        desktopServerThread.start();
    }
}